<template>
	<view>
		<UniNavBar title="消息通知" />
		<list-page @scrolltolower="scrolltolower" :loadMoreStatus="empty">
			<view class="worp">
				<u-list-item v-for="(item, index) in list" :key="item.id">
					<u-cell :title="item.title" :label="item.content"
						:value="$u.timeFormat(item.createtime, 'yyyy-mm-dd hh:MM:ss')">

					</u-cell>
				</u-list-item>
			</view>
		</list-page>

		<u-loading-page :loading="loading"></u-loading-page>
	</view>
</template>

<script>
	import UniNavBar from "@/components/uniNavbar/index.vue"
	import ListPage from "@/components/listPage/index.vue"
	// import Empty from "@/components/empty.vue"
	import {
		readNum,
		getNoticeList
	} from "../../api/im.js";

	export default {
		components: {
			UniNavBar,
			ListPage
		},
		data() {
			return {
				page: 1,
				total: 0,
				list: [],


				loading: false,
				params: {
					page: 1,
					limit: 999,
				},
				loading: false,
			}
		},
		onShow() {
			// this.getevaluation()
		},
		/**
		 * 刷新
		 */
		onPullDownRefresh() {
			this.page = 1;
			this.list = []
			this.getData()
		},
		onReachBottom() {
			if (this.list.length < this.total) {
				this.page++;
				this.getData()
			}
		},

		onLoad() {
			this.changeReadNumData()
			this.getData()
		},
		computed: {
			isLoading() {
				return this.loading === false && this.list.length != 0
			},
			empty() {
				return this.list.length === 0 && this.loading === false
			}
		},
		methods: {

			/**
			 * 网络请求
			 */
			async getData() {
				let res = await getNoticeList(this.page)
				this.total = parseInt(res.data.total)
				if (this.page == 1) {
					this.list = res.data.data
				} else {
					this.list = [...this.list, ...res.data.data]
				}
			},
			/**
			 * 未读变已读
			 */
			async changeReadNumData() {
				await readNum("notice_read")
			}
		}
	}
</script>

<style lang="scss" scoped>
	.commit_box {
		background: #FFFFFF;
		box-shadow: 1px 10px 9px 0px rgba(133, 133, 133, 0.04);
		border-radius: 10px;
		min-height: 210rpx;
		width: 702rpx;
		margin-bottom: 30rpx;

		.c_worp {
			padding: 18rpx 0;
		}

		.c_title {
			font-size: 35rpx;
			font-family: Microsoft YaHei;
			font-weight: 400;
			text-align: center;
			color: #666666;
		}

		.commit_v {
			display: flex;
			align-items: center;
			margin-top: 50rpx;

			.commit_v_c {
				flex: 1;
				display: flex;
				flex-direction: column;
				justify-content: center;
				align-items: center;

				.c_number {
					font-size: 45rpx;
					font-family: Microsoft YaHei;
					font-weight: 400;
					color: #6750F8;
					margin-bottom: 21rpx;
				}

				.c_text {
					font-size: 30rpx;
					font-family: Microsoft YaHei;
					font-weight: 400;
					color: #444444;
				}
			}
		}
	}
</style>